/**
 * @description 单例设计模式
 */

var obj = {} //对象字面量创建的对象就是单例

var Singleon = (function(){
    function F(name){
       this.name = name   
    }
    var instance=null;
    return function(name){
        if(!instance){
            instance = new F(name);
        }
        return instance
    }
})()
var obj1 = Singleon('obj1');
var obj2 = Singleon('obj2');
console.log(obj1.name);
console.log(obj2.name)
console.log(obj1 == obj2)

console.log('****************')

var Singleon1; 
(function(){
    var instance;
    Singleon1=function(name){
        if(instance){
          return instance
        }   
        this.name = name
        instance = this
    } 
})();
var obj3 = new Singleon1('obj3');
var obj4 = new Singleon1('obj4');
console.log(obj3.name);
console.log(obj4.name)
console.log(obj3 == obj4)



function debounce(fn){
    return function(...args){
        let timer  = null;
        if(timer) clearTimeOut(timer)
        timer = setTimeOut(()=>{
            fn.apply(this,args)
        })
    }
}



Promise.resolve(1).then((res)=>{
    console.log(res)
    return 2
}).catch((err)=>{
    return 3
}).then((res)=>{
    console.log(res)
})